
namespace=ebike_registry
version=latest
server=registry.cn-hangzhou.aliyuncs.com
hub_user=深圳市豆点云科技术有限公司
hub_pwd=dev%ddyk@219_i

echo "checking go program..."

go version
if [ $? -eq 1 ]
then
  echo "go is not installed"
  exit
fi

echo "checking docker program..."

docker --version

if [ $? -eq 1 ]
then
  echo "docker is not installed"
  exit
fi


# apps=(aggregation auth manager shadow signal statistic)
 apps=(aggregation auth manager shadow signal)
#apps=(shadow)

echo "checking app directory..."

# 检查app目录
for app in "${apps[@]}"
do
  if ! [ -e $app ]
  then
      echo "$app doesn't exist"
      exit
  elif ! [ -d $app ]
  then
    echo "$app isn't directory"
    exit
  elif ! [ -r $app ]
  then
    echo "$app isn't readable"
    exit
  fi
done

echo "building and pushing app images"

# 构建镜像并推送
for app in "${apps[@]}"
do
  echo "build $app image..."
  docker build -t ${namespace}/${app}:${version} --platform linux/amd64 --build-arg APP=${app} .

  echo  "push $app image..."
  docker login -u ${hub_user} -p ${hub_pwd} ${server}
  docker tag ${namespace}/${app}:${version} ${server}/${namespace}/${app}:${version}
  docker push ${server}/${namespace}/${app}:${version}
done

echo "Done!"


